package com.dsteiner.widgets.client;

import java.util.Stack;

import com.dsteiner.widgets.client.Widgets.SimplePanelExt;
import com.dsteiner.widgets.client.resources.WidgetsResources;
import com.google.gwt.user.client.ui.RootPanel;

public class GlassPane extends SimplePanelExt{

	private static GlassPane instance;
	private Stack<Boolean> visibilityStack = new Stack<Boolean>();
	
	private GlassPane() {
		setStyleName(WidgetsResources.INSTANCE.css().overlayPanel());
	}
	
	public static GlassPane getInstance(){
		if(instance == null){
			instance = new GlassPane();
		}
		return instance;
	}
	
	@Override
	public void setVisible(boolean visible) {
		if(visible)
			visibilityStack.add(true);
		else
			visibilityStack.pop();
		
		visible = !visibilityStack.isEmpty();
		super.setVisible(visible);
		
		if(visible && !isAttached()){
			RootPanel.get().add(this);
		}
	}
}
